<%@page import="com.sbdcpn.utils.factory.FactoryUtil,com.sbdcpn.utils.db.BaseDAO"%>
<%
	//String strSQL = "select sum(t_fina_give_send_detail.out_sum) as pagenum from t_fina_give_send_detail";
	String strSQL = "select nvl(sum(t_fina_give_send_detail.out_sum),0.00) as pagenum,nvl(sum(t_fina_give_send_detail.send_qty),0.00) as send_qty from t_fina_give_send_detail";
	String strWhere = RequestUtil.getStringParameter(request ,"where_sql");
	String strValue = RequestUtil.getStringParameter(request ,"where_value");
	String strType = RequestUtil.getStringParameter(request ,"where_type");

	//if  (!strWhere.equals("")) {
	//	strWhere += " AND (((in_material.auditing ='1' and in_material.is_audited='2' and (is_record='0' or is_record is null))))  group by in_material.provider_id,in_material.cost_unit_id,in_material.provider_code,in_material.provider_name order by provider_id)";
	//} else {
	//	strWhere = "((in_material.auditing ='1' and in_material.is_audited='2' and (is_record='0' or is_record is null)))  group by in_material.provider_id,in_material.cost_unit_id,in_material.provider_code,in_material.provider_name order by provider_id)";
	//}

	BaseDAO dao = BaseDAO.getInstance();

	Map mpCnt = null;
	Map mpCntste = null;
	Map mpCntmat = null;
	if (strWhere.indexOf("notDoQuery") == -1) {
		if (!strValue.equals("")) {
			//mpCnt = dao.queryOneRow(strSQL + " where " + strWhere ,new String[]{strValue ,strType});
			mpCnt = dao.queryOneRow(strSQL + " where material_diff not in ('03','04') and " + strWhere ,new String[]{strValue ,strType});
			//System.out.println("==========STESQL=="+ strSQL + " where material_diff = '04'  and " + strWhere + "===========strtype"+ strType  +"=======strvalue=" + strValue);
			mpCntste = dao.queryOneRow(strSQL + " where material_diff = '04'  and " + strWhere ,new String[]{strValue ,strType});
			mpCntmat = dao.queryOneRow(strSQL + " where material_diff = '03'  and  " + strWhere ,new String[]{strValue ,strType});
		} else {
			//mpCnt = dao.queryOneRow(strSQL + " where " + strWhere);
			mpCnt = dao.queryOneRow(strSQL + " where  not in ('03','04') and  " + strWhere);
			//System.out.println("==========STESQL=="+ strSQL + " where material_diff = '04'  and " + strWhere);
			mpCntste = dao.queryOneRow(strSQL + " where material_diff = '04'  and  " + strWhere);
			mpCntmat = dao.queryOneRow(strSQL + " where material_diff = '03'  and  " + strWhere);
		}
	} else {
		mpCnt = FactoryUtil.newMap();
		mpCntste = FactoryUtil.newMap();
		mpCntmat = FactoryUtil.newMap();
		mpCnt.put("pagenum" ,"0.00");
		mpCntste.put("pagenum" ,"0.00");
		mpCntmat.put("pagenum" ,"0.00");
		mpCnt.put("send_qty" ,"0.00");
		mpCntste.put("send_qty" ,"0.00");
		mpCntmat.put("send_qty" ,"0.00");
	}

	//System.out.println("mpCnt = " + mpCnt);
	/*(account_flag = ? and (cost_unit_id = ?))
	[EAM2004] 2004-10-11 23:18:21 strCntSQL = select sum(cntnum) as pagenum from (select in_material.provider_code ,in_material.provider_name ,in_material.cost_unit_id ,count(provider_id) as cntnum ,in_material.provider_id  from in_material WHERE  (cost_unit_id = ?) and ((in_material.auditing ='1' and in_material.is_audited='2' and (is_record='0' or is_record is null)))  group by in_material.provider_id,in_material.cost_unit_id,in_material.provider_code,in_material.provider_name order by provider_id)
	*/
%>


<SCRIPT LANGUAGE="JavaScript">
<!--
function f_account(){


	var leftObj = window.top.frames("treeFrame");
	//alert(leftObj.location);
	var endDate = document.all("end_date").value;
	var beginDate = document.all("begin_date").value;
	var costUnitID = document.all("cost_unit").value;
	if (beginDate == "" || beginDate == null) return ;
	if (endDate == "" || endDate == null) return ;

/*
	var paramUrl = "?funcid=FINANCE_OUT_BILL_TDATE";
	paramUrl += "&pageType=grid";
	paramUrl += "&where_sql=t_finance_dept_unio_date.send_date = ?";
	paramUrl += "&where_type=string";
	paramUrl += "&where_value=" +date ;
	//paramUrl += "&=";
*/
	var paramUrl = "?end_date=" + endDate;
	paramUrl += "&begin_date=" + beginDate;
	paramUrl += "&costUnitID=" + costUnitID;
	var href = leftObj.location.href.split("?")[0];

	leftObj.location.href = href + paramUrl;
	document.all("where_sql").value = "notDoQuery";
	document.all("extend_param").value = beginDate + ";" + endDate;
	f_reloadPage();
}

function f_setGrid() {
	f_setTotalDate();
}

function f_setTotalDate() {
	
	var currentdate = getToday().split("-");
	var var_year = currentdate[0];
	var var_month = currentdate[1];
	var var_date = currentdate[2];
	if (var_month.length == 1)  var_month = "0"+var_month;
	if (var_date.length == 1) var_date = "0" +var_date;


	var account_date = document.all("extend_param").value;
	if (account_date == "") {
		document.all("begin_date").value = var_year+"-"+var_month+"-"+var_date;
		document.all("end_date").value = var_year+"-"+var_month+"-"+var_date;
	} else {
		account_date = account_date.split(";");
		document.all("begin_date").value = account_date[0];
		document.all("end_date").value = account_date[1];
	}
}

//-->
</SCRIPT>
<table class="gridTbl">
<tr class="gridData">
	<td class="gridData" ><label id="totalDate"><eam:message key = "text.total.totalDate"/>(YYYY-MM-DD):</label>

<input type="text" name="begin_date" value="" size="10" >-<input type="text" name="end_date" value="" size="10" >
	<SELECT NAME="cost_unit">
	<option value=""></option>
	<%
		String strGetCostUnit  = "select cost_unit_id ,cost_unit_name from base_cost_unit order by cost_unit_id";
		//System.out.println(strGetCostUnit);
		List listCostUnit  = dao.query(strGetCostUnit);
		Map mapCostUnit = null;
		String strCostUnit = null;
		String strCostUnitID = null;
		for (int kk = 0 ,mm = listCostUnit.size();kk < mm;kk++){
			mapCostUnit = (Map)listCostUnit.get(kk);
			strCostUnit = (String)mapCostUnit.get("cost_unit_name");
			strCostUnitID = (String)mapCostUnit.get("cost_unit_id");
			//System.out.println(strCostUnit);
	%>
	<option value="<%=strCostUnitID%>"><%=strCostUnit%></option>
	<%}%>
	</SELECT>
<input type="button" name="btnAccount" value="<eam:message key="btn.total2" />" onclick="f_account();">
	<eam:message key="steelement.report.money" />(<eam:message key="text.finance.device" />):<%=(String)mpCnt.get("pagenum")%>
	<eam:message key="text.finance.quantity" />(<eam:message key="default.ste.material" />):<%=(String)mpCntste.get("send_qty")%>
	<eam:message key="steelement.report.money" />(<eam:message key="default.ste.material" />):<%=(String)mpCntste.get("pagenum")%>
    <eam:message key="text.finance.quantity" />(<eam:message key="text.finance.mat" />):<%=(String)mpCntmat.get("send_qty")%>
    <eam:message key="steelement.report.money" />(<eam:message key="text.finance.mat" />):<%=(String)mpCntmat.get("pagenum")%>

</TD>
</TR>
</TABLE>
